package File;

import java.io.File;
import java.io.FileFilter;

/*
    获取file包中大小超过1000字节的所有子项
    输出这些子项的名字和实际占用的字节数

 */
public class Test3 {
    public static void main(String[] args) {

//        FileFilter fileFilter=new FileFilter() {//过滤器
//            @Override
//            public boolean accept(File pathname) {
//                return pathname.length()>1000;//字节大于1000的子项
//            }
//        };
//
//
//        File file = new File("./src/main/java/file");
//        if (file.isDirectory()){
//            File[] subs = file.listFiles(fileFilter);
//            for (int i = 0; i < subs.length; i++) {
//                File sub = subs[i];
//                System.out.println(sub.getName()+": "+sub.length()+"字节");
//            }
//        }
        File file = new File("./src/main/java/file");
        if (file.isDirectory()){
            File[] subs = file.listFiles(new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    return pathname.length()>1000;
                }
            });
            for (int i = 0; i < subs.length; i++) {
                File sub = subs[i];
                System.out.println(sub.getName()+": "+sub.length()+"字节");
            }
        }
    }
}
